package com.tanguy.driver.utlis;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * Created by dab on 2017/10/30 0030 15:55
 */

public class TimeUtils {
    /**
     * yyyy-MM-dd
     */
    public static final String TIME_YYYY_MM_DD = "yyyy-MM-dd";
    /**
     * yyyy-MM-dd HH:mm
     */
    public static final String TIME_YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
    public static final String HH_MM = "HH:mm";
    public static final String TIME_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
    public static final String TIME_MM_DD_HH_MM = "MM月dd日 HH:mm";
    public static final String TIME_YYYY_MM_DD_HH_MM_01 = "yyyy年MM月dd日 HH:mm";
    public static final String TIME_MM_DD = "MM月dd日";

    /**
     * 获取日期(几月几号)
     *
     * @param integer
     * @param pattern
     * @return
     */
    public static String getDays(int integer, String pattern) {
        Date date = new Date();//取时间
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE, integer);//把日期往后增加一天.整数往后推,负数往前移动
        date = calendar.getTime(); //这个时间就是日期往后推一天的结果
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);
        String dateString = formatter.format(date);
        return dateString;
    }

    public static String getDays(int integer) {
        return getDays(integer, TIME_YYYY_MM_DD);
    }

    public static String getWeek() {
        Calendar calendar = Calendar.getInstance();
        int week = calendar.get(Calendar.DAY_OF_WEEK);
        switch (week) {
            case 1:return "星期日";
            case 2:return "星期一";
            case 3:return "星期二";
            case 4:return "星期三";
            case 5:return "星期四";
            case 6:return "星期五";
            default:return "星期六";
        }
    }
    /**
     * 将时间转换为时间戳
     *
     * @param s
     * @return
     */
    public static long dateToStamp(String s) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-ddHH时mm分");
        long timestamp = 0;
        try {
            Date date = simpleDateFormat.parse(s);
            timestamp = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return timestamp;
    }
}
